package com.topisv.tms.repository.stock.instorage;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.stock.instorage.InstorageUpSubTaskItem;

/**
 * 上架子任务分配明细_dao
 * @author cc
 *
 */
public interface InstorageUpDispatchSubTaskItemDao extends PagingAndSortingRepository<InstorageUpSubTaskItem, Long>, JpaSpecificationExecutor<InstorageUpSubTaskItem> {

	List<InstorageUpSubTaskItem> findByTaskCode(String taskCode);

	List<InstorageUpSubTaskItem> findBySubTaskCode(String subTaskCode);
	
	@Modifying
	@Query("delete from InstorageUpSubTaskItem t where t.subTaskCode = ?1 ")
	void deleteBySubTaskCode(String subTaskCode);
	
	@Query("select t from InstorageUpSubTaskItem t where t.subTaskCode = ?1 and t.skuCode =?2")
	List<InstorageUpSubTaskItem> findBySubTaskCodeAndSkuCode(String subTaskCode, String skuCode);
	
	@Query("select t from InstorageUpSubTaskItem t where t.subTaskCode = ?1 and t.skuCode =?2 "
	    + "and (t.batchCode = ?3 or t.batchCode is null or t.batchCode = '') "
	    + "and (t.productDate = ?4 or t.productDate is null or t.productDate = '') "
	    + "and (t.expireDate = ?5 or t.expireDate is null or t.expireDate = '')")
    List<InstorageUpSubTaskItem> findBySubTaskCodeAndSkuCodeNew(String subTaskCode, String skuCode, String batchCode, String productDate, String expireDate);

	@Query("select t from InstorageUpSubTaskItem t where t.subTaskCode = ?1 and t.skuCode = ?2 and t.errorFlag= ?3 ")
    InstorageUpSubTaskItem findByNew(String subTaskCode, String skuCode, String errorFlag);
	
}